package com.glsc.ngateway.platform.controller;

import cn.hutool.core.util.StrUtil;
import com.glsc.ngateway.common.api.platform.resp.PlatformResponse;
import com.glsc.ngateway.common.api.shortmsg.bo.MessageGenericVo;
import com.glsc.ngateway.common.api.shortmsg.feign.IFeignShortmsgService;
import com.glsc.ngateway.common.base.exception.PlatformException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

@RestController
@RequestMapping("/api/validService")
public class ServiceValidController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private IFeignShortmsgService shortmsgService;


    @PostMapping("/sendWeixinMessage")
    public PlatformResponse sendSmsDemo(@RequestBody @NotNull MessageGenericVo messageGenericVo) {
        logger.info("企微应用消息：{}", messageGenericVo);
        if(StrUtil.isEmpty(messageGenericVo.getAgentId())||StrUtil.isEmpty(messageGenericVo.getTextContent())){
            throw PlatformException.error("企微应用消息发送目的AgentId或者发送内容不能为空" );
        }
        String response = shortmsgService.sendAgentMessageGeneric(messageGenericVo);

        return PlatformResponse.successData(response);
    }

}
